package com.tanhua.server.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 添加自定义的拦截器
     * addPathPatterns()
     *   1. 指定拦截的资源
     *   2. /** 表示拦截所有路径及其子路径，比如/user,/user/a/b/c
     * excludePathPatterns()
     *   1. 指定放行的资源。也就是哪些资源不拦截
     *   2. 一般登陆、注册这些页面及提交地址不需要拦截，可以直接访问
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/loginVerification");
    }
}
